/*
 * Created by SharpDevelop.
 */
using System;
using System.Collections.Generic;

namespace MiniMIPS
{
	/// <summary>
	/// Description of Register.
	/// </summary>
	/// 
	
	//destination registers
	public enum RegsD { r1=1, r2, r3, r4, r5, r6, LEDs};
	//source registers
	public enum RegsS { r0, r1, r2, r3, r4, r5, r6, SWs};

	public class RegisterIO : Register
	{
		private int m_get_value;
		
		public RegisterIO()
		{
			m_get_value = 0;
		}
		
		public override int Value 
		{
			get { return m_get_value; }
			set { base.Value = value; }
		}
		
		
		public int SetValue
		{
			get
			{
				return m_value;
			}
			set
			{
				base.Value = value;
			}
		}
		
		public int GetValue
		{
			get
			{
				return m_get_value;
			}
			set
			{
				m_get_value = Int8.Signed(value);
			}
		}
	}
	
	public class Register
	{
		protected int m_value;
	
		public Register()
		{
			m_value = 0;
		}
		
		public virtual int Value
		{
			get
			{
				return m_value;
			}
			set
			{
				m_value = Int8.Signed(value);
			}
		}
		
		public virtual int UValue
		{
			get
			{
				return Int8.Unsigned(m_value);
			}
		}
		
		public override bool Equals(object obj)
		{
			if(obj is Register)
			{
				Register r = (Register)obj;
				
				return r.Value == this.Value;
			}
			else
			{
				return false;
			}
		}
		
		public override int GetHashCode()
		{
			return this.Value.GetHashCode();
		}
	}
	
	public static class Int8
	{
		public static int Signed(int i)
		{
			int mod = i % 256;
			if(mod >= 128)
			{
				return mod - 256;
			}
			else
			{
				return mod;
			}
		}
		
		public static int Unsigned(int i)
		{
			int val = Signed(i);
			
			if(val < 0)
			{
				return (256 + val);
			}
			else
			{
				return val;
			}
		}
	}
	
}
